package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.ProductBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.PushBuilder;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    /**订单页面 */
    @Autowired
    private IOrderService orderService;
    /**添加订单 */
    @RequestMapping("add")
    public String addOrder(OrderBean order, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        order.setUserId(user.getUserId());
        orderService.addOrder(order);
        return "ok";
    }
    /**分页查询订单 */
    @RequestMapping("findByItem")
    public IPage<OrderBean> findByItem(Integer pageNO, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        return orderService.findByItem(pageNO,user.getUserId());
    }
    /**按订单id查询订单详情 */
    @RequestMapping("findById")
    public OrderBean findById(Integer orderId){
        return orderService.findById(orderId);
    }
    /** 展示所有订单*/
    @RequestMapping("showAll")
    public List<OrderBean> showAll(){
        return orderService.showAll();
    }

    /**（结账）修改订单状态*/
    @RequestMapping("updateStatus")
    public String updateStatus(Integer orderId){
        orderService.updateStatus(orderId);
        return "ok";
    }
    /**管理员动态条件分页查询订单 */
    @RequestMapping("cutByItem")
    public IPage<ProductBean> cutByItem(Integer pageNO, String status, LocalDate startDate,LocalDate endDate){
        return orderService.cutByItem(pageNO, status, startDate, endDate);
    }
    /**修改订单状态（发货）*/
    @RequestMapping("managerUpdateStatus")
    public String managerUpdateStatus(Integer orderId){
        orderService.managerUpdateStatus(orderId);
        return "ok";
    }
}
